package com.adopapa.nezhacloud.authc.domain;

import com.adopapa.nezhacloud.ddd.codegen.CodeGen;
import com.adopapa.nezhacloud.ddd.domain.BaseUuidEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;

@Entity
@Table(name = "AUTHC_RESOURCE")
public class ResourceInfo extends BaseUuidEntity {

	private static final long serialVersionUID = 6888218726852201034L;

	@CodeGen(query = "%", form = true, label = "资源名称")
	@Column(name = "RESOURCE_NAME")
	private String resourceName;
	@CodeGen(query = "=", form = true, required = true, type = CodeGen.TYPE_ENUM, label = "资源类型")
	@Column(name = "RESOURCE_TYPE")
	private ResourceType resourceType;
	@CodeGen(query = "=", form = true, label = "资源路径")
	@Column(name = "RESOURCE_URL", unique = true)
	private String resourceUrl;
	@CodeGen(query = "=", form = true, label = "前端路径")
	@Column(name = "FRONT_URL", unique = true)
	private String frontUrl;
	@CodeGen(form = true, label = "备注")
	@Lob
	@Column(name = "REMARK")
	private String remark;

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public ResourceType getResourceType() {
		return resourceType;
	}

	public void setResourceType(ResourceType resourceType) {
		this.resourceType = resourceType;
	}

	public String getResourceUrl() {
		return resourceUrl;
	}

	public void setResourceUrl(String resourceUrl) {
		this.resourceUrl = resourceUrl;
	}

	public String getFrontUrl() {
		return frontUrl;
	}

	public void setFrontUrl(String frontUrl) {
		this.frontUrl = frontUrl;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	//////////////////////////////////////////////////////////////////////
	public static enum ResourceType {
		MENU("菜单"), API("接口"),;

		private String title;

		private ResourceType(String title) {
			this.title = title;
		}

		public String getName() {
			return name();
		}

		public String getTitle() {
			return this.title;
		}

		public static ResourceType getEnum(String resourceType) {
			try {
				return ResourceType.valueOf(resourceType);
			} catch (Exception e) {
				return null;
			}
		}
	}

}
